<template>
  <div class="detail">
    <product-param :title="datailList.name"></product-param>
    <div class="container">
      <div class="item">
        <div class="swiper-box">
          <swiper class="swiper" :options="swiperOption">
            <swiper-slide
              ><img src="/imgs/detail/phone-1.jpg" alt=""
            /></swiper-slide>
            <swiper-slide
              ><img src="/imgs/detail/phone-2.jpg" alt=""
            /></swiper-slide>
            <swiper-slide
              ><img src="/imgs/detail/phone-3.jpg" alt=""
            /></swiper-slide>
            <swiper-slide
              ><img src="/imgs/detail/phone-4.jpg" alt=""
            /></swiper-slide>
            <div class="swiper-pagination" slot="pagination"></div>
          </swiper>
        </div>
        <div class="item-list">
          <h2>{{ datailList.name }}</h2>
          <p class="item-info">
            相机全新升级 / 960帧超慢动作 / 手持超级夜景 / 全球首款双频GPS /
            骁龙845处理器 / 红<br />
            外人脸解锁 / AI变焦双摄 / 三星 AMOLED 屏
          </p>
          <p class="info-one">小米自营</p>
          <p class="item-price">
            {{ datailList.price }}元
            <span class="price-before">{{ datailList.price + 200 }}元 </span>
          </p>
          <div class="line"></div>
          <div class="item-address">
            <span class="icon-loc"></span>
            <p>北京 北京市 朝阳区 安定门街道</p>
            <p>有现货</p>
          </div>
          <div class="banben">
            <h3>选择版本</h3>
            <div
              class="phone"
              :class="{ checked: version == 1 }"
              @click="version = 1"
            >
              6GB+64GB 全网通
            </div>
            <div
              class="phone"
              :class="{ checked: version == 2 }"
              @click="version = 2"
            >
              4GB+64GB 移动4G
            </div>
          </div>
          <div class="item-color">
            <h3>选择颜色</h3>

            <div class="phone checked">
              <span class="icon-color"></span>
              深空灰
            </div>
          </div>
          <div class="item-total">
            <div class="wraaper">
              <div class="total-info">
                {{ datailList.name }}
                {{ version == 1 ? "6GB+64GB 全网通" : "4GB+64GB 移动4G" }}
                深灰色
              </div>
              <div class="total-price">{{ datailList.price }}元</div>
            </div>
            <div class="phone-total">总计:{{ datailList.price }}元</div>
          </div>
          <div class="btn-box">
            <a href="javascript:;" class="btn btn-huge" @click="addCart"
              >加入购物车</a
            >
          </div>
        </div>
      </div>
    </div>
    <div class="price-info">
      <div class="container">
        <h3>价格说明</h3>
        <img src="/imgs/detail/item-price.jpeg" alt="" />
      </div>
    </div>
    <service-bar></service-bar>
  </div>
</template>

<script>
import ProductParam from "../components/ProductParam";
import ServiceBar from "../components/ServiceBar";
import { Swiper, SwiperSlide } from "vue-awesome-swiper";
import "swiper/swiper-bundle.css";
export default {
  name: "detail",
  components: {
    ProductParam,
    Swiper,
    SwiperSlide,
    ServiceBar,
  },
  data() {
    return {
      datailList: "",
      version: 1,
      swiperOption: {
        pagination: {
          el: ".swiper-pagination",
          dynamicBullets: true,
        },
      },
    };
  },
  mounted() {
    this.getDatailList();
  },
  methods: {
    getDatailList() {
      let id = this.$route.params.id;
      this.axios.get("/products/" + id).then((res) => {
        this.datailList = res;
      });
    },
    addCart(){
      let id = this.$route.params.id;
      this.axios.post('/carts',{
        productId:id,
        selected: true
      }).then((ret={cartProductVoList:0}) => {
        this.$store.dispatch('saveCartCount',ret.cartTotalQuantity)
        this.$router.push('/cart')
      })
    }
  },
};
</script>

<style lang="scss" scpoed>
@import "./../assets/scss/config.scss";
@import "./../assets/scss/mixin.scss";
.detail {
  .container {
    .item {
      display: flex;
      justify-content: space-between;
      .swiper-box {
        width: 642px;
        height: 642px;
        img {
          width: 642px;
          height: 642px;
        }
      }
      .item-list {
        width: 584px;
        h2 {
          font-size: 28px;
          padding-top: 28px;
          padding-bottom: 16px;
        }
        .item-info {
          font-size: 14px;
          height: 36px;
        }
        .info-one {
          font-size: 16px;
          color: $colorA;
          margin-top: 26px;
          margin-bottom: 14px;
          height: 16px;
        }
        .item-price {
          color: $colorA;
          font-size: 20px;
          .price-before {
            font-size: 16px;
            color: #999;
            margin-left: 10px;
            text-decoration: line-through;
          }
        }
        .line {
          height: 0;
          margin-top: 25px;
          margin-bottom: 28px;
          border-top: 1px solid #e5e5e5;
        }
        .item-address {
          height: 108px;
          box-sizing: border-box;
          background-color: #fafafa;
          border: 1px solid #e5e5e5;
          font-size: 14px;
          line-height: 14px;
          position: relative;
          padding-top: 31px;
          padding-left: 64px;
          .icon-loc {
            @include bgImg(20px, 20px, "/imgs/detail/icon-loc.png");
            position: absolute;
            top: 27px;
            left: 34px;
          }
          p {
            color: #666666;
            &:last-child {
              margin-top: 15px;
              color: $colorA;
            }
          }
        }
        .banben {
          h3 {
            font-size: 18px;
            margin: 20px 0;
          }
          .phone {
            box-sizing: border-box;
            width: 287px;
            height: 50px;
            font-size: 14px;
            color: #333333;
            display: inline-block;
            cursor: pointer;
            line-height: 50px;
            text-align: center;
            border: 1px solid #e5e5e5;
            margin-right: 10px;
            &:last-child {
              margin-right: 0;
            }
            &.checked {
              color: $colorA;
              border: 1px solid $colorA;
            }
          }
        }
        .item-color {
          h3 {
            font-size: 18px;
            margin: 20px 0;
          }
          .phone {
            box-sizing: border-box;
            width: 287px;
            height: 50px;
            font-size: 14px;
            color: #333333;
            display: inline-block;
            cursor: pointer;
            line-height: 50px;
            text-align: center;
            border: 1px solid #e5e5e5;
            margin-right: 10px;

            &:last-child {
              margin-right: 0;
            }
            &.checked {
              color: $colorA;
              border: 1px solid $colorA;
            }
          }
        }
        .item-total {
          height: 108px;
          margin: 50px 0 30px;
          padding: 24px 33px 29px 30px;
          background: #fafafa;
          box-sizing: border-box;
          .wraaper {
            @include flex();
          }
          .phone-total {
            font-size: 24px;
            margin-top: 18px;
            color: $colorA;
          }
        }
      }
    }
  }
  .price-info {
    background-color: #f3f3f3;
    height: 340px;
    margin-top: 30px;
    h3 {
      font-size: 24px;
      color: #333333;
      padding-top: 38px;
      margin-bottom: 30px;
    }
  }
}
</style>
